package com.xyy.saas.payment.cores.vo;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Getter
@Setter
public class QueryAccountBalanceDO implements Serializable {
    private static final long serialVersionUID = 2050119184279838628L;

    private String businessUserId;

    private String businessIdType;

    private String businessOrderType;

    private String userId;

    private String thirdUserId;

    /**
     * 查询开始时间
     */
    private String beginTime;

    /**
     * 查询截至时间
     */
    private String endTime;

    /**
     * 页码
     */
    private int pageNo;

    /**
     * 兼容富民2.0 2022-06-07 -> 2022-06-07 00:00:00
     * @param dateTime
     * @return
     */
    public static String fixDateTime(String dateTime) {
        try {
            return format(parse(dateTime, DATEFORMATDAY), DATEFORMATSECOND);
        }
        catch(Exception ex) {
            return dateTime;
        }
    }

    public static void main(String[] args) {
        System.out.println(fixDateTime("2022-06-07"));
        System.out.println(fixDateTime("2022-06-07 00:00:00"));
    }

    private static String DATEFORMATDAY = "yyyy-MM-dd";
    private static String DATEFORMATSECOND = "yyyy-MM-dd HH:mm:ss";

    private static String format(Date date, String format) {
        if(date == null) {
            return null;
        }

        return new SimpleDateFormat(format).format(date);
    }

    private static Date parse(String string, String format) throws ParseException {
        if(string == null || string.equals("")) {
            return null;
        }

        return new SimpleDateFormat(format).parse(string);
    }
}
